package com.foreveross.vo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.format.annotation.DateTimeFormat;

import com.foreveross.common.Constants;
import com.foreveross.util.DateUtil;
import com.foreveross.util.NotSerialize;

@Entity
@Table(name = "hr_favorable", catalog = "hrtenement")
public class HrFavorable implements java.io.Serializable {

	private String id;
	private String name;
	private String type;
	private String title;
	private String image;
	private String imagePath;
	private String content;
	private String contentImgList;
	private Double price;
	private HrBusiness businessId;
	@NotSerialize
	private SysUser publisherId;
	@NotSerialize
	private SysUser createId;
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date createTime;
	private HrHouses houseId;
	private Double favorablePrice;
	private Integer saleCount;
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date saleBeginTime;
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date saleEndTime;
	private String isShowBusiness;
	private String isPublish;
	private boolean saleStatus;
	private Object other;
	private Integer isAll;

	private List<FavorableHouse> favorableHouses = new ArrayList<FavorableHouse>();
	
	public HrFavorable() {
	}
	
	public HrFavorable(String id) {
		this.id = id;
	}
	
	@Id
	@GenericGenerator(name = "idGenerator", strategy = "uuid")
	@GeneratedValue(generator = "idGenerator")
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	 
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}
	
	@Transient
	public String getImagePath() {
		return this.imagePath ;
	}
	
	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	@Column(name = "content_img_list")
	public String getContentImgList() {
		return contentImgList;
	}

	public void setContentImgList(String contentImgList) {
		this.contentImgList = contentImgList;
	}
	
	@Column(name = "is_all")
	public Integer getIsAll() {
		return isAll;
	}

	public void setIsAll(Integer isAll) {
		this.isAll = isAll;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "business_id")
	@NotFound(action=NotFoundAction.IGNORE)
	public HrBusiness getBusinessId() {
		return businessId;
	}

	public void setBusinessId(HrBusiness businessId) {
		this.businessId = businessId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "publisher_id")
	@NotFound(action=NotFoundAction.IGNORE)
	public SysUser getPublisherId() {
		return publisherId;
	}

	public void setPublisherId(SysUser publisherId) {
		this.publisherId = publisherId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "create_id")
	@NotFound(action=NotFoundAction.IGNORE)
	public SysUser getCreateId() {
		return createId;
	}

	public void setCreateId(SysUser createId) {
		this.createId = createId;
	}

	
	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "house_id")
	@NotFound(action=NotFoundAction.IGNORE)
	public HrHouses getHouseId() {
		return houseId;
	}

	public void setHouseId(HrHouses houseId) {
		this.houseId = houseId;
	}

	@Column(name = "favorable_price")
	public Double getFavorablePrice() {
		return favorablePrice;
	}

	public void setFavorablePrice(Double favorablePrice) {
		this.favorablePrice = favorablePrice;
	}

	@Column(name = "sale_count")
	public Integer getSaleCount() {
		return saleCount;
	}

	public void setSaleCount(Integer saleCount) {
		this.saleCount = saleCount;
	}
	
	@Column(name = "sale_begin_time")
	public Date getSaleBeginTime() {
		return saleBeginTime;
	}

	public void setSaleBeginTime(Date saleBeginTime) {
		this.saleBeginTime = saleBeginTime;
	}

	@Column(name = "sale_end_time")
	public Date getSaleEndTime() {
		Date date = new Date();
		if(null != saleBeginTime && null != saleEndTime && 
			date.before(saleEndTime) && date.after(saleBeginTime)){
			saleStatus = true;
		}else{
			saleStatus = false;
		}
		
		return saleEndTime;
	}

	public void setSaleEndTime(Date saleEndTime) {
		this.saleEndTime = saleEndTime;
	}
	
	@Column(name = "isShowBusiness")
	public String getIsShowBusiness() {
		return isShowBusiness;
	}

	public void setIsShowBusiness(String isShowBusiness) {
		this.isShowBusiness = isShowBusiness;
	}
	
	@Column(name = "isPublish")
	public String getIsPublish() {
		return isPublish;
	}

	public void setIsPublish(String isPublish) {
		this.isPublish = isPublish;
	}

	@Transient
	public boolean getSaleStatus() {
		return saleStatus;
	}

	public void setSaleStatus(boolean saleStatus) {
		this.saleStatus = saleStatus;
	}

	@Transient
	public Object getOther() {
		return other;
	}

	public void setOther(Object other) {
		this.other = other;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "favorable")
	public List<FavorableHouse> getFavorableHouses() {
		return favorableHouses;
	}

	public void setFavorableHouses(List<FavorableHouse> favorableHouses) {
		this.favorableHouses = favorableHouses;
	}

}
